package com.foreknow.elmboot.mapper;



import com.foreknow.elmboot.po.Cart;
import org.apache.ibatis.annotations.*;

import java.util.List;
@Mapper
public interface CartMapper {
    /**
     * 向购物车中添加数据
     * @param cart
     * @return
     * @throws Exception
     */
    @Insert("insert into cart(foodId,businessId,userId,quantity) values(#{foodId},#{businessId},#{userId},1)")
    public int saveCart(Cart cart)throws Exception;

    /**
     * 更新数量
     * @param cart
     * @return
     * @throws Exception
     */
    @Update("update cart set quantity=#{quantity} where userId=#{userId} and businessId=#{businessId} and foodId=#{foodId}")
    public int updateCart(Cart cart) throws Exception;



    /**
     * 查询购物车中的信息
     * @param cart
     * @return
     * @throws Exception
     */

    public List<Cart> listCart(Cart cart)throws Exception;

    /**
     * 向购物车中删除数据
     * @param cart
     * @return
     * @throws Exception
     */
    @Delete("delete from cart where userId=#{userId} and businessId=#{businessId} and foodId=#{foodId}")
    public int deleteCart(Cart cart)throws Exception;
}
